package com.nsession.common;

import com.nsession.response.CommonResponse;
import lombok.Data;

/**
 * Created by hp on 2016/4/7.
 */
@Data
public class ErrorHolder {
    private String resCode;
    private String resMsg;

    public ErrorHolder(ErrorDef errorDef) {
        this.resCode = errorDef.getCode();
        this.resMsg = errorDef.getDesc();
    }

    public ErrorHolder(String resCode, String resMsg) {
        this.resCode = resCode;
        this.resMsg = resMsg;
    }

    public static void setError(CommonResponse response, ErrorHolder errorHolder) {
        response.setResultCode(errorHolder.getResCode());
        response.setResultDesc(errorHolder.getResMsg());
    }

    public static void setError(CommonResponse response, ErrorDef errorDef, Object... params) {
        response.setResultCode(errorDef.getCode());
        response.setResultDesc(String.format(errorDef.getDesc(), params));
    }
}
